package com.woniuxy.caradmin.controller;


import com.woniuxy.caradmin.entity.pojo.Dept;
import com.woniuxy.caradmin.mapper.DeptMapper;
import com.woniuxy.caradmin.service.DeptService;
import com.woniuxy.caradmin.util.R;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import com.woniuxy.caradmin.entity.pojo.Dept;
import com.woniuxy.caradmin.exception.CarException;
import com.woniuxy.caradmin.service.DeptService;
import com.woniuxy.caradmin.util.Constaint;
import com.woniuxy.caradmin.util.R;
import com.woniuxy.caradmin.util.ResultCode;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import com.woniuxy.caradmin.entity.pojo.Dept;
import com.woniuxy.caradmin.service.DeptService;
import com.woniuxy.caradmin.util.R;
import com.woniuxy.caradmin.util.ResultCode;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

/**
 * <p>
 *  前端控制器
 * </p>
 *
 * @author womenzu
 * @since 2020-12-07
 */
@RestController
@RequestMapping("/dept")
public class DeptController {
      @Autowired
    private DeptService deptService;
      @GetMapping("deptselectAll")
    public R deptselectAll(){
          List<Dept> depts = deptService.selectAllDept();

          if(depts!=null&&depts.size()>0){
              return R.ok().data("depts",depts);
          }else {
              return null;
          }
      }

    @ApiOperation(value = "获取车辆部门")
    @GetMapping(value = "/getdept")
    public R getdept(){
        List<Dept> deptList = deptService.selectAllDept();
        if(deptList!=null&&deptList.size()>0){
            return R.ok().data("deptList",deptList);
        }else{
            throw new CarException(ResultCode.ERROR, Constaint.ERROR);
        }
    }
    @GetMapping("/depts")
    @ApiOperation("查询所有的部门")
    public R selectAllDept(){
        List<Dept> depts = deptService.selectAllDept();
        if (depts!=null&&depts.size()>0){
            return R.ok().data("depts",depts);
        }
        return null;
    }
}

